'use strict'

const { Sequelize , Op, Model } = require('sequelize');
const fs = require('fs');

let sequelize = new Sequelize("usefortest" , "postgres" , "123456" , {
    host : "baoxinru.top",//120.76.228.84
    dialect : " postgres"
})

let file = fs.readdirSync(__dirname);
let getfile = file.filter(item=>{
    return item.endsWith(".js") && item !== 'index.js'
});

let result = {};
getfile.forEach(item=>{
    let modelname = item.replace(".js" , "");
    let model = require(__dirname + '/' + modelname);
    result[modelname] = sequelize.define(modelname.toLocaleLowerCase(),model);
})

result.sequelize = sequelize;

result.sync = async function(){
    return await sequelize.sync({force : true});
}

module.exports = result;